import * as mockjs from "mockjs";
import { createHash } from 'crypto';
import * as moment from "moment";

const IHelper = new class {
  hash(len?: number): string {
    const length: number = len ? len : 6
    const lower: string = "abcdefghighlmnopqrstuvwxyz"
    const upper: string = lower.toUpperCase()
    const number: string = "0123456789"
    const pool: string = `${number}${upper}${lower}`
    return mockjs.Random.string(lower, 1) + mockjs.Random.string(pool, length - 1)
  }
  md5(l: string): string {
    return createHash('md5').update(l).digest('hex')
  }

  unix(): number {
    return moment().unix()
  }

  convertToQueryString(params: object): string {
    return Object.keys(params).map(k => `${k}=${params[k]}`).join("&")
  }

  timeFormatted(format?: string) {
    return moment().format(format || "YYYY-MM-DD HH:mm:ss")
  }

  getArray(len: number): number[] {
    return Array.from(new Array(len).keys())
  }

  writeToConfig() {}
}

export default IHelper